﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace demo
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());
            Thread mythread = new Thread(ThreadMain);
            mythread.Start();
        }

        private static void ThreadMain()
        {
            while (true)
            {
                string appStartPath = System.Windows.Forms.Application.StartupPath + "\\Pantovis.exe";
                string appName = "Pantovis";//the path of the exe file
                bool runFlag = false;
                Process[] myProcesses = Process.GetProcesses();
                foreach (Process myProcess in myProcesses)
                {
                    if (myProcess.ProcessName.CompareTo(appName) == 0)
                    {
                        runFlag = true;
                    }

                }

                if (!runFlag)   //如果程序没有启动
                {
                    Process proc = new Process();
                    proc.StartInfo.FileName = appName;
                    proc.StartInfo.WorkingDirectory = Path.GetDirectoryName(appStartPath);
                    proc.Start();
                }

                Thread.Sleep(1000);
            }
        }
    }
}
